<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>脚标机监控记录</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <!-- App favicon -->
    <link rel="shortcut icon" href="assets/images/favicon.ico">

    <!-- App css -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/icons.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/metismenu.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="assets/css/custom.css" />
    <!-- layer插件 -->
    <link rel="stylesheet" type="text/css" href="plugins/layer2.4/skin/layer.css" />

    <!-- bootstrap-select -->
    <link rel="stylesheet" type="text/css" href="plugins/bootstrap-select/css/bootstrap-select.min.css" />

    <script src="assets/js/modernizr.min.js"></script>

</head>

<body>

    <!-- Begin page -->
    <div id="wrapper">

        <!-- ============================================================== -->
        <!-- 页面内容开始 -->
        <!-- ============================================================== -->

        <!-- Start Page content -->
        <div class="my-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card-box">
                            <h4 class="m-t-0 m-b-30 header-title">脚标机监控记录</h4>

                            <form class="form-horizontal" role="form">
                                <div class="form-group row">
                                    <label for="barcodeMachineId" class="col-3 col-form-label">脚标机编号</label>
                                    <div class="col-9">
                                        <input readonly="readonly" type="text" class="form-control"
                                            id="barcodeMachineId" name="barcodeMachineId" placeholder="脚标机编号">
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="loginDate" class="col-3 col-form-label">登录时间</label>
                                    <div class="col-9">
                                        <input readonly="readonly" type="text" class="form-control" id="loginDate"
                                            name="loginDate" placeholder="登录时间">
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="state" class="col-3 col-form-label">在线状态</label>
                                    <div class="col-9">
                                        <input readonly="readonly" type="text" class="form-control" id="state"
                                            name="state" placeholder="在线状态">
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="barcodeSurplus" class="col-3 col-form-label">条码剩余数量</label>
                                    <div class="col-9">
                                        <input readonly="readonly" type="text" class="form-control" id="barcodeSurplus"
                                            name="barcodeSurplus" placeholder="条码剩余数量">
                                    </div>
                                </div>
                                <!-- <div class="form-group row">
									<label for="threshold" class="col-3 col-form-label">条码剩余数量阈值</label>
									<div class="col-9">
										<input readonly="readonly" type="text" class="form-control" id="threshold"
											name="threshold" placeholder="条码剩余数量阈值">
									</div>
								</div> -->
                                <div class="form-group row">
                                    <label for="userId" class="col-3 col-form-label">用户</label>
                                    <div class="col-9">
                                        <select class="selectpicker form-control" id="userId" name="userId" title="用户" data-hide-disabled="ture" data-actions-box="true" disabled="disabled">
										</select>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="offlineTime" class="col-3 col-form-label">下线时间</label>
                                    <div class="col-9">
                                        <input readonly="readonly" type="text" class="form-control" id="offlineTime"
                                            name="offlineTime" placeholder="下线时间">
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="createBy" class="col-3 col-form-label">创建者</label>
                                    <div class="col-9">
                                        <input readonly="readonly" type="text" class="form-control" id="createBy"
                                            name="createBy" placeholder="创建者">
                                    </div>
                                </div>
                                <div class="form-group mb-0 justify-content-end row">
                                    <div class="col-9">
                                        <button type="button" onclick="layer_close()"
                                            class="btn btn-danger waves-effect">关闭</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <!-- #### -->
                        <div class="card-box">

                            <div class="content">
                                <div class="container-fluid">
                                    <div class="row">
                                        <div class="col-12">
                                            <div class="card-box">
                                                <div class="card-body">
                        <button class="m-t-0 float-left btn btn-primary radius" onclick="window_show('添加档口信息','StallsAdd.html')"><i class="fa fa-plus"></i>添加档口信息</button>
														<button class="m-t-0 float-right btn btn-success btn-refresh radius" onclick="refresh()"><i class="fa fa-refresh fa-spin"></i></button>
                        </div>
                                                <div class="card-body">

                                                    <h4 class="m-t-0 header-title">档口信息列表</h4>
                                                    <table id="datatable" class="table table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;">
                                                        <thead>
                                                            <tr>
                                                                <th>条码编号</th>
                                                                <th>脚标机编号</th>
                                                                <th>所属禽类</th>
                                                                <th>销售终端名称</th>
                                                                <th>销售终端地址</th>
                                                                <th>贴标时间</th>
                                                            </tr>
                                                        </thead>

                                                        <tbody id="tbody">
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                        <!-- end row -->
                        </div>
                        <!-- container -->


                        </div>



                        </div>
                        <!-- #### -->
                    </div>
                </div>

            </div>
            <!-- container -->

        </div>

        <!-- ============================================================== -->
        <!-- End Right content here -->
        <!-- ============================================================== -->

    </div>
    <!-- END wrapper -->

    <!-- jQuery  -->
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/bootstrap.bundle.min.js"></script>
    <script src="assets/js/metisMenu.min.js"></script>
    <script src="assets/js/waves.js"></script>
    <script src="assets/js/jquery.slimscroll.js"></script>

    <!-- App js -->
    <script src="assets/js/custom.js" type="text/javascript" charset="utf-8"></script>
    <script src="assets/js/jquery.core.js"></script>
    <script src="assets/js/jquery.app.js"></script>
    <script src="assets/js/custom.js" type="text/javascript" charset="utf-8"></script>

    <!-- 表单验证 -->
    <script src="plugins/jquery.form.js/jquery.form.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="plugins/jquery.validation.1.14.0/jquery.validate.js" type="text/javascript" charset="utf-8"></script>
    <script src="plugins/jquery.validation.1.14.0/validate-methods.js" type="text/javascript" charset="utf-8"></script>
    <script src="plugins/jquery.validation.1.14.0/messages_zh.js" type="text/javascript" charset="utf-8"></script>
    <!-- bootstrap-select -->
    <script src="plugins/bootstrap-select/js/bootstrap-select.js" type="text/javascript" charset="utf-8"></script>


    <!-- layer插件 -->
    <script src="plugins/layer2.4/layer.js" type="text/javascript" charset="utf-8"></script>

    <!-- easyUI -->
    <script src="plugins/jquery-easyUI/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="plugins/jquery-easyUI/easyui-lang-zh_CN.js" type="text/javascript" charset="utf-8"></script>

    <!-- datatables插件 -->
    <script src="plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="plugins/datatables/dataTables.bootstrap4.min.js"></script>
    <script src="plugins/datatables/dataTables.responsive.min.js"></script>
    <script src="plugins/datatables/responsive.bootstrap4.min.js"></script>
    <script type="text/javascript">
        var datatable;
        //初始化表格
        code = get_code()
        let [detailId, barcodeMachineId] = code.split('&')

        function initData() {
            $.ajax({
                type: "GET",
                url: `${URL}PoultrySales/findAll/by/barcodeId?barcodeMachineId=${barcodeMachineId}`,
                async: false,
                dataType: "json",
                success: function(data) {
                    data = data.object
                    console.log(data)
                    for (var i = 0; i < data.length; i++) {
                        for (var key in data[i]) {
                            if (data[i][key] == null) {
                                data[i][key] = '';
                            }
                        }
                        var tbody = $('<tr class="text-c">' +
                            '<td>' + data[i].barcodeNumber + '</td>' +
                            '<td>' + data[i].poultryName + '</td>' +
                            '<td>' + data[i].barcodeMachineId + '</td>' +
                            '<td>' + data[i].salesTerminalName + '</td>' +
                            '<td>' + data[i].salesAddr + '</td>' +
                            '<td>' + formatTime(data[i].labelingDate) + '</td>' +
                            // '<td class="td-manage">' +
                            // '<a title="明细" href="javascript:;" onclick="window_change(\'明细\',\'StallsDetial.html\',\'' + data[i].id + '\')"><i class="fa fa-th-list"></i>明细</a>' +
                            // '<a title="编辑" href="javascript:;" onclick="window_change(\'编辑\',\'StallsEdit.html\',\'' + data[i].id + '\')" class="ml-1" style="text-decoration:none"><i class="fa fa-edit "></i>编辑</a>' +
                            // '<a title="删除" href="javascript:;" onclick="del_single(\'/stalls/id?id=\',\'' + data[i].id + '\')" class="ml-1" style="text-decoration:none"><i class="fa fa-trash"></i>删除</a>' +
                            // '</td>' +
                            '</tr>')
                        $("tbody").append(tbody)
                    }

                    $("#datanum").text(data.length)

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    networkError(XMLHttpRequest, textStatus, errorThrown)
                }
            });

            datatable = $('#datatable').DataTable({
                "aaSorting": [
                    [0, "desc"]
                ], //默认第几个排序
                "bStateSave": true, //状态保存
                "aoColumnDefs": [
                    //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                    {
                        "orderable": false,
                        "aTargets": [4]
                    } // 制定列不参与排序
                ]
            });
        }
        $(document).ready(function() {
            initData()
            getRole()
        })

        function refresh() {
            datatable.clear(); //销毁datatable
            datatable.destroy(); //销毁datatable
            initData() //重新加载数据
        }

        //获取用户列表
        $.ajax({
            type: "post",
            url: URL + 'findUserAll',
            async: false,
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    var options = $('<option value="' + data[i].personId + '">' + data[i].username +
                        '    [id=' + data[i].personId + ']' + '</option>')
                    $("#userId").append(options);

                }
                $('.selectpicker').selectpicker('refresh');
                $('.selectpicker').selectpicker('render');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                networkError(XMLHttpRequest, textStatus, errorThrown)
            }
        });

        //把参数回填
        $.ajax({
            type: "get",
            url: URL + 'findBarcodeMachineStatusById?id=' + detailId,
            async: false,
            dataType: "json",
            success: function (data) {
                console.log(data)
                // if (data.state == 1) {
                //     data.state = '正常'
                // } else if (data.state == 2) {
                //     data.state = '卡纸'
                // } else if (data.state == 3) {
                //     data.state = '缺纸'
                // } else {
                //     data.state = '离线'
                // }
                $("form").form('load', data);
                $('#userId').selectpicker('val', data.userId);
                // $('.selectpicker').selectpicker('refresh');
                // $('.selectpicker').selectpicker('render');
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                networkError(XMLHttpRequest, textStatus, errorThrown)
            }
        });
    </script>
    <!-- ### -->
</body>

</html>